<div class="row-content ">
	<div class="row">
		<div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
			<div class="widget-head ">
				<div class="widget-title ">
					订单详情
				</div>
			</div>
			<div class="widget__order-detail widget-body layui-col-sm12 layui-col-md12 layui-col-lg12">
				<div class="layui-col-sm12">
					<?php
                        // 计算当前步骤位置
                        $progress = 1;
                        $detail['pay_status']['value'] === 20 && $progress += 1;
                        $detail['delivery_status']['value'] === 20 && $progress += 1;
                        $detail['receipt_status']['value'] === 20 && $progress += 1;
                    ?>
					<ul class="order-detail-progress progress-{$progress} ">
						<li>
							<span>下单时间</span>
							<div class="tip">
								{$detail['create_time']}
							</div>
						</li>
						<li>
							<span>付款</span>
							{if $detail['pay_status']['value'] heq 20}
							<div class="tip">
								{$detail['pay_time']|date='Y-m-d H:i:s'}
							</div>
							{/if}
						</li>
						<li>
							<span>发货</span>
							{if $detail['delivery_status']['value'] heq 20}
							<div class="tip">
								{$detail['order_delivery'][count($detail['order_delivery'])-1]['create_time']}
							</div>
							{/if}
						</li>
						<li>
							<span>收货</span>
							{if $detail['receipt_status']['value'] heq 20}
							<div class="tip">
								{$detail['order_delivery'][0]['receipt_time']|date='Y-m-d H:i'}
							</div>
							{/if}
						</li>
						<li>
							<span>完成</span>
							{if $detail['order_status']['value'] heq 30}
							<div class="tip">
								{$detail['end_time']|date='Y-m-d H:i'}
							</div>
							{/if}
						</li>
					</ul>
				</div>
				<div class="widget-head layui-col-sm12 layui-col-md12 layui-col-lg12">
					<div class="widget-title">
						基本信息
					</div>
				</div>
				<div class="layui-col-md12">
					<table width="100%" class="layui-table">
						<thead>
						<tr>
							<th>
								订单号
							</th>
							<th>
								买家
							</th>
							<th>
								订单金额
							</th>
							<th>
								交易状态
							</th>
							{if ($detail['pay_status']['value'] heq 10 && $detail['order_status']['value'] === 10)}
							<th>
								操作
							</th>
							{/if}
						</tr>
						<tr>
							<td>
								{$detail['order_no']}
							</td>
							<td>
								<p>
									{$detail['user']['nickName']}
								</p>
								<p class="layer-link-muted">
									(用户id：{$detail['user']['user_id']})
								</p>
							</td>
							<td class="">
								<div class="td__order-price layer-text-left">
									<ul class="layer-avg-sm-2">
										<li class="layer-text-right">订单总额：</li>
										<li class="layer-text-right">￥{$detail['total_price']} </li>
									</ul>
									{if ($detail['coupon_id'] > 0)}
									<ul class="layer-avg-sm-2">
										<li class="layer-text-right">优惠券抵扣：</li>
										<li class="layer-text-right">- ￥{$detail['coupon_price']}</li>
									</ul>
									{/if}
									<ul class="layer-avg-sm-2">
										<li class="layer-text-right">运费金额：</li>
										<li class="layer-text-right">+ ￥{$detail['express_price']}</li>
									</ul>
									{if $detail['update_price']['value'] !== '0.00'}
									<ul class="layer-avg-sm-2">
										<li class="layer-text-right">后台改价：</li>
										<li class="layer-text-right">{$detail['update_price']['symbol']}
											￥{$detail['update_price']['value']}
										</li>
									</ul>
									{/if}
									<ul class="layer-avg-sm-2">
										<li class="layer-text-right">实付款金额：</li>
										<li class="x-color-red layer-text-right">
											￥{$detail['pay_price']}
										</li>
									</ul>
								</div>
							</td>
							<td>
								<p>
									付款状态：
									<span class="layer-badge {$detail['pay_status']['value'] === 20 ? 'layer-badge-success' : ''}">
											{$detail['pay_status']['text']}
								</span>
								</p>
								<p>
									发货状态：
									<span class="layer-badge {$detail['delivery_status']['value'] === 20 ? 'layer-badge-success' : ''}">
											{$detail['delivery_status']['text']}
								</span>
								</p>
								<p>
									收货状态：
									<span class="layer-badge {$detail['receipt_status']['value'] === 20 ? 'layer-badge-success' : ''}">
											{$detail['receipt_status']['text']}
								</span>
								</p>
							</td>
							{if ($detail['pay_status']['value'] === 10 && $detail['order_status']['value'] === 10)}
							<td>
								<p class="layer-text-center">
									<a class="j-update-price" href="javascript:void(0);" data-order_id="{$detail['order_id']}" data-order_price="{$detail['total_price'] - $detail['coupon_price'] + $detail['update_price']['value']}" data-express_price="{$detail['express_price']}">修改价格</a>
								</p>
							</td>
							{/if}
						</tr>
						</tbody>
					</table>
				</div>
				<div class="widget-head layui-col-sm12 layui-col-md12 layui-col-lg12">
					<div class="widget-title ">
						商品信息
					</div>
				</div>
				<div class="layui-col-md12">
					<table width="100%" class="layui-table">
						<thead>
						<tr>
							<th>
								商品名称
							</th>
							<th>
								商品编码
							</th>
							<th>
								重量(Kg)
							</th>
							<th>
								单价
							</th>
							<th>
								购买数量
							</th>
							<th>
								商品总价
							</th>
						</tr>
						{foreach $detail['goods'] as $Item}
						<tr>
							<td class="goods-detail layer-text-middle">
								<div class="goods-image">
									<img src="{$Item['image']}" alt="">
								</div>
								<div class="goods-info">
									<p class="goods-title">
										{$Item['name']}
									</p>
									<p class="goods-spec layer-link-muted">
										{$Item['goods_attr']}
									</p>
								</div>
							</td>
							<td>
								{$Item['goods_no'] ?: '--' }
							</td>
							<td>
								{$Item['goods_weight'] ?: '--'}
							</td>
							<td>
								￥{$Item['goods_price']}
							</td>
							<td>
								×{$Item['total_num']}
							</td>
							<td>
								￥{$Item['total_price']}
							</td>
						</tr>
						{/foreach}
						<tr>
							<td colspan="6" class="layer-text-right ">
								<span class="">买家留言：{$detail['buyer_remark'] ?: '无' }</span>
								<span class="layer-fr">总计金额：￥{$detail['total_price']}</span>
							</td>
						</tr>
						</tbody>
					</table>
				</div>
				<div class="widget-head layui-col-sm12 layui-col-md12 layui-col-lg12">
					<div class="widget-title ">
						收货信息
					</div>
				</div>
				<div class="layui-col-md12">
					<table width="100%" class="layui-table">
						<thead>
						<tr>
							<th>
								收货人
							</th>
							<th>
								收货电话
							</th>
							<th>
								收货地址
							</th>
						</tr>
						<tr>
							<td>
								{$detail['address']['name']}
							</td>
							<td>
								{$detail['address']['phone']}
							</td>
							<td>
								{$detail['address']['region']['province']}
								{$detail['address']['region']['city']}
								{$detail['address']['region']['region']}
								{$detail['address']['detail']}
							</td>
						</tr>
						</tbody>
					</table>
				</div>
				{if $detail['pay_status']['value'] heq 20}
				<div class="widget-head layui-col-sm12 layui-col-md12 layui-col-lg12">
					<div class="widget-title ">
						付款信息
					</div>
				</div>
				<div class="layui-col-md12">
					<table width="100%" class="layui-table">
						<thead>
						<tr>
							<th>
								应付款金额
							</th>
							<th>
								支付方式
							</th>
							<th>
								支付流水号
							</th>
							<th>
								付款状态
							</th>
							<th>
								付款时间
							</th>
						</tr>
						</thead>
						<tbody>
						<tr>
							<td>
								￥{$detail['pay_price']}
							</td>
							<td>
								微信支付
							</td>
							<td>
								{$detail['transaction_id'] ?: '--'}
							</td>
							<td>
							<span class="layer-badge {$detail['pay_status']['value'] === 20 ? 'layer-badge-success' : ''}">
												{$detail['pay_status']['text']}
							</span>
							</td>
							<td>
								{$detail['pay_time'] ? date('Y-m-d H:i:s', $detail['pay_time']) : '--'}
							</td>
						</tr>
						</tbody>
					</table>
				</div>
				{/if}
				{if $detail['pay_status']['value'] === 20 || $detail['pay_status']['value'] === 40}
				<div class="widget-head layui-col-sm12 layui-col-md12 layui-col-lg12">
					<div class="widget-title">
						物流信息
					</div>
				</div>
				<div class="layui-col-md12">
					<table class="layui-table">
						<thead>
						<tr>
							<th>
								物流公司
							</th>
							<th>
								物流单号
							</th>
							<th>
								类型
							</th>
							<th>
								发货时间
							</th>
							<th>
								收货时间
							</th>
						</tr>
						<tbody>
						{volist name="detail.order_delivery" id="vo"}
						<tr>
							<td>
								{$vo['company']}
							</td>
							<td>
								{$vo['express_no']}
							</td>
							<td>
								{if $vo.type ==1}卖家发货{else/}买家退货{/if}
							</td>
							<td>
								{$vo.create_time}
							</td>
							<td>
								{if $vo.receipt_time} {$vo.receipt_time|date='Y-m-d H:i'}{/if}
							</td>
						</tr>
						{/volist}
						</tbody>
					</table>
				</div>
				{/if}
				<!-- 去发货 -->
				{if $detail.delivery_status eq 10}
				<form id="my-form" class="layui-form" method="post" action="{:url('order/delivery', ['order_id' =>
					 $detail['order_id']])}">
					<div class="layui-form-item">
						<label class="layui-form-label form-require">物流公司 </label>
						<div class="layui-col-sm9 layer-u-end layer-padding-top-xs">
							<select name="order[express_id]" data-am-selected="{btnSize: 'sm', maxHeight: 240}" required>
								<option value=""></option>
								{if (isset($express_list))}{foreach $express_list as $expres}
								<option value="{$expres['express_id']}">
									{$expres['express_name']}
								</option>
								{/foreach} {/if}
							</select>
							<div class="help-block layer-margin-top-xs">
								<small>可在 <a href="{:url('setting/express')}" target="_blank">物流公司列表</a>
									中设置
								</small>
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label form-require">物流单号 </label>
						<div class="layui-col-sm9 layer-u-end">
							<input type="text" class="layui-input" name="order[express_no]" required>
						</div>
					</div>
					<div class="layui-form-item">
						<button type="submit" class="j-submit layui-btn">
							确认发货
						</button>
					</div>
				</form>
				{/if}
			</div>
		</div>
	</div>
</div>
<script id="tpl-update-price" type="text/template">
	<div class="layer-padding-top-sm">
		<form id="money-form" class="form-update-price layer-form tpl-form-line-form" method="post"
			  action="{:url('order/updatePrice', ['order_id' => $detail['order_id']])}">
			<div class="layui-form-item">
				<label class="layui-col-sm3 layer-form-label"> 订单金额 </label>
				<div class="layui-col-sm9">
					<input type="number" min="0.00" class="tpl-form-input" name="order[update_price]"
						   value="{{ order_price }}">
					<small>最终付款价 = 订单金额 + 运费金额</small>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-col-sm3 layer-form-label"> 运费金额 </label>
				<div class="layui-col-sm9">
					<input type="number" min="0.00" class="tpl-form-input" name="order[update_express_price]"
						   value="{{ express_price }}">
				</div>
			</div>
		</form>
	</div>
</script>
<script>
    $(function () {
        /**
         * 修改价格
         */
        $('.j-update-price').click(function () {
            var $this = $(this);
            var data = $this.data();
            // var orderId = $(this).data('order_id');
            layer.open({
                type: 1
                , title: '订单价格修改'
                , area: '340px'
                , offset: 'auto'
                , anim: 1
                , closeBtn: 1
                , shade: 0.3
                , btn: ['确定', '取消']
                , content: template('tpl-update-price', data)
                , success: function (layero) {
                }
                , yes: function (index) {
                    // console.log('asdasd');
                    // 表单提交
                    $('.form-update-price').ajaxSubmit({
                        type: "post",
                        dataType: "json",
                        success: function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url)
                                : $.show_error(result.msg);
                        }
                    });
                    layer.close(index);
                }
            });
        });
        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();
        $('#money-form').superForm();
    });
</script>